import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/brn_row1_delegate.dart';

import 'effective_data_widget.dart';

class PeakAndPlateauTimeWidget extends StatelessWidget {
  final BuildContext context;
  final String title;
  final String electricityTypeSting;
  String startTime;
  String endTime;
  final bool isDelete;
  final Function(String startDateTime, String endDateTime) timeChooseCallBack;
  final Function() btnClickCallBack;
  final Function(String) typeClickCallBack;
  PeakAndPlateauTimeWidget(
      this.context,
      this.title,
      this.electricityTypeSting,
      this.startTime,
      this.endTime,
      this.timeChooseCallBack,
      this.btnClickCallBack,
      this.typeClickCallBack,
      {this.isDelete = false,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    String type = '';
    if (electricityTypeSting == '0') {
      type = ResKey.siteSettingElectricityShape.tr;
    } else if (electricityTypeSting == '1') {
      type = ResKey.siteSettingElectricityPeak.tr;
    } else if (electricityTypeSting == '2') {
      type = ResKey.siteSettingElectricityAverage.tr;
    } else if (electricityTypeSting == '3') {
      type = ResKey.siteSettingElectricityValley.tr;
    }
    Log.d('PeakAndPlateauTimeWidgetstartTime==' + startTime.toString());
    return SizedBox(
      height: 100,
      child: Column(
        children: [
          Gaps.vGap5,
          EffectiveDataWidget(
            context,
            title,
            startTime,
            endTime,
            (startDateTime, endDateTime) {
              timeChooseCallBack(startDateTime, endDateTime);
            },
            () {
              btnClickCallBack();
            },
            isShowHour: true,
            isEdit: true,
            isDelete: isDelete,
            isRequired: true,
          ),

          Container(
            child: Row(
              children: [
                 Container(
                   color: Colors.white,
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(
                    left: 6.w,
                    right: 2.w,
                  ),
                  child: Text(
                    '*',
                    style: ytTextStyle(
                      color: Colour.warningTextColor,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
                Container(
                  width: 90.w,
                  child: Text(
                    ResKey.siteSettingElectricityPriceType.tr,
                    maxLines: 2,
                    style: ytTextStyle(
                        fontWeight: FontWeight.normal,
                        color: Colour.otherTextColor,
                        fontSize: 14),
                  ),
                ),
                // Gaps.hGap10,
                GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      showBottomPop([
                        ResKey.siteSettingElectricityShape.tr,
                        ResKey.siteSettingElectricityPeak.tr,
                        ResKey.siteSettingElectricityAverage.tr,
                        ResKey.siteSettingElectricityValley.tr
                      ]);
                      // typeClickCallBack();
                    },
                    child: Container(
                      decoration: const BoxDecoration(
                          color: Colour.backgroundColor,
                          borderRadius: BorderRadius.all(Radius.circular(4))),
                      height: 32,
                      width: 106.w - 15.w,
                      alignment: Alignment.center,
                      child: Text(
                        type,
                        style: ytTextStyle(
                            fontWeight: FontWeight.normal, fontSize: 14),
                      ),
                    )),
                Spacer()
              ],
            ),
          ),
          Spacer(),
          // Container(
          //   height: 1,
          //   // margin: EdgeInsets.only(left: 16.w, right: 16.w),
          //   color: Colour.dividerColor,
          // ),
        ],
      ),
    );
  }

  ///弹出底部弹窗
  showBottomPop(List<String> list) {
    BrnMultiDataPicker(
      context: Get.context!,
      title: title,
      confirmClick: (indexList) {
        Log.d('indexList==' + indexList[0].toString());
        typeClickCallBack(indexList[0].toString());
      },
      delegate: Brn1RowDelegate(list),
    ).show();
  }
}
